{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "a = np.random.rand(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.45960864, 0.19456448])"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.3080946581361779"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(sum(np.square(a - 0.5))) ** 0.5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.3080946581361779"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.linalg.norm(a-0.5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "numpy.ndarray"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(np.random.rand(2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "centre_circle = (0.5, 0.5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "def in_circle(point):\n",
    "    # (sum(np.square(a - 0.5))) ** 0.5\n",
    "    if np.linalg.norm(point - 0.5) > 0.5:\n",
    "        return False\n",
    "    return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3.15208\n"
     ]
    }
   ],
   "source": [
    "n = 10 ** 5\n",
    "s = 0\n",
    "for i in range(n):\n",
    "    if in_circle(np.random.rand(2)):\n",
    "        s += 1\n",
    "print(s / n / 0.25)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [],
   "source": [
    "b = np.random.rand(9, 2, )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.03609252, 0.57507738],\n",
       "       [0.96319562, 0.07355831],\n",
       "       [0.33264351, 0.50459777],\n",
       "       [0.07261562, 0.30158887],\n",
       "       [0.83263413, 0.78838689],\n",
       "       [0.26595526, 0.95290059],\n",
       "       [0.07960703, 0.31302614],\n",
       "       [0.85460791, 0.05924924],\n",
       "       [0.74451585, 0.73185628]])"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-0.46390748,  0.07507738],\n",
       "       [ 0.46319562, -0.42644169],\n",
       "       [-0.16735649,  0.00459777],\n",
       "       [-0.42738438, -0.19841113],\n",
       "       [ 0.33263413,  0.28838689],\n",
       "       [-0.23404474,  0.45290059],\n",
       "       [-0.42039297, -0.18697386],\n",
       "       [ 0.35460791, -0.44075076],\n",
       "       [ 0.24451585,  0.23185628]])"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b-0.5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-0.2152101499999504"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "-0.46390748 ** 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[2.15210153e-01, 5.63661354e-03],\n",
       "       [2.14550186e-01, 1.81852513e-01],\n",
       "       [2.80081960e-02, 2.11394659e-05],\n",
       "       [1.82657404e-01, 3.93669746e-02],\n",
       "       [1.10645462e-01, 8.31669957e-02],\n",
       "       [5.47769392e-02, 2.05118949e-01],\n",
       "       [1.76730253e-01, 3.49592262e-02],\n",
       "       [1.25746772e-01, 1.94261236e-01],\n",
       "       [5.97880011e-02, 5.37573350e-02]])"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.square(b-0.5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.46994337, 0.62960519, 0.16741964, 0.47119463, 0.44024136,\n",
       "       0.50979985, 0.46009725, 0.5656925 , 0.33696489])"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sqrt(np.sum(np.square(b-(0.5, 0.5)), axis=1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [],
   "source": [
    "x = np.sqrt(np.sum(np.square(b-(0.5, 0.5)), axis=1))\n",
    "c = x > 0.5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(np.extract(c, x))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "ml_env",
   "language": "python",
   "name": "ml_env"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.1"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
